package com.whnk.web.controller.pm.project_manage;

import java.util.List;

import com.whnk.pm.domain.OutsourceInfo;
import com.whnk.pm.service.IOutsourceInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.whnk.common.annotation.Log;
import com.whnk.common.enums.BusinessType;

import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.common.base.AjaxResult;
import org.springframework.web.multipart.MultipartFile;

/**
 * 外包人员基本 信息操作处理
 * 
 * @author whwhnk
 * @date 2020-01-08
 */
@Controller
@RequestMapping("/pm/outsourceInfo")
public class OutsourceInfoController extends BaseController
{
    private String prefix = "pm/outsourceInfo";
	
	@Autowired
	private IOutsourceInfoService outsourceInfoService;
	
	@RequiresPermissions("pm:outsourceInfo:view")
	@GetMapping()
	public String outsourceInfo()
	{
	    return prefix + "/outsourceInfo";
	}
	
	/**
	 * 查询外包人员基本列表
	 */
	@RequiresPermissions("pm:outsourceInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(OutsourceInfo outsourceInfo)
	{
		startPage();
        List<OutsourceInfo> list = outsourceInfoService.selectOutsourceInfoList(outsourceInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增外包人员基本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存外包人员基本
	 */
	@RequiresPermissions("pm:outsourceInfo:add")
	@Log(title = "外包人员基本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(OutsourceInfo outsourceInfo)
	{		
		return toAjax(outsourceInfoService.insertOutsourceInfo(outsourceInfo));
	}

	/**
	 * 修改外包人员基本
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		OutsourceInfo outsourceInfo = outsourceInfoService.selectOutsourceInfoById(id);
		mmap.put("outsourceInfo", outsourceInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存外包人员基本
	 */
	@RequiresPermissions("pm:outsourceInfo:edit")
	@Log(title = "外包人员基本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(OutsourceInfo outsourceInfo)
	{		
		return toAjax(outsourceInfoService.updateOutsourceInfo(outsourceInfo));
	}
	
	/**
	 * 删除外包人员基本
	 */
	@RequiresPermissions("pm:outsourceInfo:remove")
	@Log(title = "外包人员基本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(outsourceInfoService.deleteOutsourceInfoByIds(ids));
	}

	@Log(title = "Excel导入外包人员信息", businessType = BusinessType.UPDATE)
	@PostMapping("/upload")
	@ResponseBody
	public AjaxResult signExcelFileUpload(@RequestParam("signFileUpload") MultipartFile file) throws Exception {
		outsourceInfoService.outsourceExcelFileUpload(file);
		return success();
	}

}
